import { http } from '../api/axios';
import { Task } from '../contexts/types';

/**
 * 获取任务列表
 */
export const getTasks = async (): Promise<Task[]> => {
  const response = await http.get<Task[]>('/tasks/');
  return response;
};

/**
 * 创建新任务
 */
export const createTask = async (task: Omit<Task, 'id' | 'createdAt'>): Promise<Task> => {
  const response = await http.post<Task>('/tasks/', task);
  return response;
};

/**
 * 更新任务
 */
export const updateTask = async (id: string, task: Partial<Task>): Promise<Task> => {
  const response = await http.put<Task>(`/tasks/${id}`, task);
  return response;
};

/**
 * 删除任务
 */
export const deleteTask = async (id: string): Promise<void> => {
  await http.delete(`/tasks/${id}`);
};

// 导出所有任务相关操作
const taskService = {
  getTasks,
  createTask,
  updateTask,
  deleteTask,
};

export default taskService; 